package com.example.kimasi.recite.manager;

import com.example.kimasi.recite.ReciteInfo;
import com.example.kimasi.recite.aaatools.LogUtils;

/**
 * 任务单词的自动朗读管理
 * Created by kimasi on 2016/4/13.
 */
public class ReadAloudManager {

    public Boolean canEnRead = true;
    public Boolean canCnRead = false;

    public void readAloud() {
        new Thread() {
            @Override
            public void run() {
                int i = 0;
                while (ReciteInfo.getIsReadAloud()) {
                    LogUtils.v2("在念英文 "+i + ReciteInfo.taskWords.get(i).getEn());
                    ReciteInfo.getReciteInfo().getPronounce().pronounce2
                            (ReciteInfo.taskWords.get(i).getEn()+";"+inciseEn(ReciteInfo.taskWords.get(i).getEn())+
                              inciseCn(ReciteInfo.taskWords.get(i).getCn()));

                   // LogUtils.v2("在念中文 " + i);  //要判断文本不为空
                   // canCnRead = false;
                  //  canEnRead = ReciteInfo.getReciteInfo().getPronounce().pronounce2 //会漏掉,加判断
                  //          (ReciteInfo.taskWords.get(i).getCn());

                    i++;
                    try {
                        Thread.sleep(20);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }.start();
    }

    public String inciseEn(String s){
        String string[] = s.split("||");
        String s1="";
        for (String s2:string){
            s1+=s2+", ";
        }
        LogUtils.v2("切割en"+s1);
        return s1;
    }
    public String inciseCn(String s){
        String string[] = s.split("n.|vt.|adj.|vi.|v.| +");
        String s1=" ";
        for (String s2:string){
            s1+=s2;
        }
        LogUtils.v2("切割"+s1);
        return s1;
    }
}
